<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/22
 */

namespace App\Models;

use App\Filters\AdminLogFilter;
use App\Traits\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
 * 管理员操作日志模型
 * Class AdminLog
 * @package App\Models
 */
class AdminLog extends Model
{
    use BaseModel, HasFactory;

    /**
     * 指定表名
     */
    protected $table = 'admin_log';

    /**
     * 能批量赋值的属性
     *
     * @var string[]
     */
//    protected $fillable = [];

    /**
     * 不能被批量赋值的属性
     *
     * @var array
     */
    protected $guarded = [];

    /**
     * 数据显示时，设置了敏感信息字段数据中不显示
     *
     * @var array
     */
    protected $hidden = [
    ];

    /**
     * 显示数据时类型转换
     *
     * @var array
     */
    protected $casts = [
    ];

    /**
     * 关联管理员信息
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function user()
    {
        return $this->belongsTo(User::class,'created_user_id', 'id');
    }

    /**
     * 不自动更新updated_at
     * @return string|void|null
     */
    public function getUpdatedAtColumn()
    {
        return null;
    }

    /**
     * 注册过滤器
     * @param $query
     * @param AdminLogFilter $filters
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeFilter($query, AdminLogFilter $filters)
    {
        return $filters->apply($query);
    }
}
